package at.fhj.itm10.ticketmaster.beans;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;

import at.fhj.itm10.ticketmaster.dao.DAOException;
import at.fhj.itm10.ticketmaster.dao.DAOFactory;
import at.fhj.itm10.ticketmaster.dao.OrderDAO;
import at.fhj.itm10.ticketmaster.dao.impl.DAOFactoryImpl;
import at.fhj.itm10.ticketmaster.models.Order;

/**
 * @author 	Martin Kropf
 * @since	November 2012
 */

@ManagedBean
@RequestScoped
public class OrderBean {

	private OrderDAO dao;
	private Order order;
	
	public OrderBean(){
		init();

	}
	
	@PostConstruct
	public void init(){
		try {
			// getDAO
			DAOFactory daoFactoryImpl;
			daoFactoryImpl = new DAOFactoryImpl();
			setDao(daoFactoryImpl.getOrderDAO());

		} catch (DAOException e) {
			e.printStackTrace();
		}
		
	}

	public OrderDAO getDao() {
		return dao;
	}

	public void setDao(OrderDAO dao) {
		this.dao = dao;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) throws DAOException {
		this.order = order;
		
		dao.insert(order);
	}
}
